//
//  GTWeChatDynamicItemModel.m
//  GTW
//
//  Created by Ran on 15/11/12.
//  Copyright (c) 2015年 xcode. All rights reserved.
//

#import "GTWeChatDynamicItemModel.h"

#import "GTWeChatDynamicTopView.h"
#import "GTWeChatDynamicContentView.h"
#import "GTWeChatDynamicImageContainerView.h"
#import "GTWeChatDynamicAtView.h"
#import "GTWeChatDynamicTuple.h"
#import "GTWeChatDynamicLinkView.h"
#import "GTWeChatDynamicTagView.h"
#import "GTWeChatDynamicLikeAndCommentView.h"

@implementation GTWeChatDynamicItemModel

#pragma mark - Setter

- (void)setSourceData:(RanTestModel *)sourceData
{
    _sourceData = sourceData;
    [self loadData];
}

- (void)loadData
{
    CGFloat leftSpacing = 10;
    CGFloat rightSpacing = 10;
    CGFloat spacingTop = 10;
    CGFloat spacingBottom = 10;
    CGFloat spacingBetweenTopViewAndContentContainer = 10;
    CGFloat spacingBetweenContentContainerAndImageContainer = 10;
    CGFloat spacingBetweenImageContainerAndAtView = 10;
    CGFloat spacingBetweenAtViewAndLinkView = 10;
    CGFloat spacingBetweenLinkViewAndTagView = 10;
    CGFloat spacingBetweenTagViewAndLikeView = 10;
    
    CGFloat theWidth = [UIScreen mainScreen].bounds.size.width - leftSpacing - rightSpacing;
    
    GTWeChatDynamicTuple *topViewTuple = [GTWeChatDynamicTopView getProcessedDataFromSourceData:self.sourceData withWidth:theWidth];
    self.dataForTopView = topViewTuple.data;
    self.frameForTopView = CGRectMake(leftSpacing, spacingTop, theWidth, topViewTuple.height);
    
    id contentSourceData = self.dataForContentView? self.dataForContentView: self.sourceData;
    GTWeChatDynamicTuple *contentTuple = [GTWeChatDynamicContentView getProcessedDataFromSourceData:contentSourceData withWidth:theWidth];
    self.dataForContentView = contentTuple.data;
    self.frameForContentView = CGRectMake(leftSpacing, CGRectGetMaxY(self.frameForTopView) + spacingBetweenTopViewAndContentContainer, theWidth, contentTuple.height);
    
    GTWeChatDynamicTuple *imageTuple = [GTWeChatDynamicImageContainerView getProcessedDataFromSourceData:self.sourceData withWidth:theWidth];
    self.dataForImageContainerView = imageTuple.data;
    self.frameForImageContainerView = CGRectMake(leftSpacing, CGRectGetMaxY(self.frameForContentView) + spacingBetweenContentContainerAndImageContainer, theWidth, imageTuple.height);
    
    GTWeChatDynamicTuple *atViewTuple = [GTWeChatDynamicAtView getProcessedDataFromSourceData:self.sourceData withWidth:theWidth];
    self.dataForAtView = atViewTuple.data;
    self.frameForAtView = CGRectMake(leftSpacing, CGRectGetMaxY(self.frameForImageContainerView) + spacingBetweenImageContainerAndAtView, theWidth, atViewTuple.height);
    
    GTWeChatDynamicTuple *linkViewTuple = [GTWeChatDynamicLinkView getProcessedDataFromSourceData:self.sourceData withWidth:theWidth];
    self.dataForLinkView = linkViewTuple.data;
    self.frameForLinkView = CGRectMake(leftSpacing, CGRectGetMaxY(self.frameForAtView) + spacingBetweenAtViewAndLinkView, theWidth, linkViewTuple.height);
    
    GTWeChatDynamicTuple *tagViewTuple = [GTWeChatDynamicTagView getProcessedDataFromSourceData:self.sourceData withWidth:theWidth];
    self.dataForTagView = tagViewTuple.data;
    self.frameForTagView = CGRectMake(leftSpacing, CGRectGetMaxY(self.frameForLinkView) + spacingBetweenLinkViewAndTagView, theWidth, tagViewTuple.height);
    
    self.height = CGRectGetMaxY(self.frameForTagView) + spacingBottom;
}

@end
